package com.log530_projetfinal;

import java.util.Map;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Window;
import android.widget.TextView;

public class SettingsActivity extends Activity implements TabListener, Fragments.OnItemSelectedListener {

	private Fragments fragPlante = new Fragments("Plante", 1);
	private Fragments fragLapin = new Fragments("Lapin", 2);
	private Fragments fragLoup = new Fragments("Loup", 3);

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

		setContentView(R.layout.test);

		// Configuration de la barre d'onglet
		getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		getActionBar().addTab(getActionBar().newTab().setText(fragPlante.getName()).setTabListener(this));
		getActionBar().addTab(getActionBar().newTab().setText(fragLapin.getName()).setTabListener(this));
		getActionBar().addTab(getActionBar().newTab().setText(fragLoup.getName()).setTabListener(this));
		
		
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {

	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {

		if (tab.getText().equals(fragPlante.getName())) {
			ft.replace(R.id.fragmentContainer, fragPlante);
		} else if (tab.getText().equals(fragLapin.getName())) {
			ft.replace(R.id.fragmentContainer, fragLapin);
		} else if (tab.getText().equals(fragLoup.getName())) {
			ft.replace(R.id.fragmentContainer, fragLoup);
		}
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {

	}

	@Override
	public void onRssItemSelectedPlantes(Map<Integer, TextView> mapValues) {
		Intent intent = new Intent();

		intent.putExtra("plante1", (mapValues.get(1).getText() == "") ? "0" : mapValues.get(1).getText());
		intent.putExtra("plante2", (mapValues.get(2).getText() == "") ? "0" : mapValues.get(2).getText());
		intent.putExtra("plante3", (mapValues.get(3).getText() == "") ? "0" : mapValues.get(3).getText());
		intent.putExtra("plante4", (mapValues.get(4).getText() == "") ? "0" : mapValues.get(4).getText());
		intent.putExtra("plante5", (mapValues.get(5).getText() == "") ? "0" : mapValues.get(5).getText());
		intent.putExtra("plante6", (mapValues.get(6).getText() == "") ? "0" : mapValues.get(6).getText());
		setResult(RESULT_OK, intent);
	}

	@Override
	public void onRssItemSelectedLapins(Map<Integer, TextView> mapValues) {
		Intent intent = new Intent();
		Log.i("output", "blablabla:::::" + mapValues.get(1).getText());

		System.out.println("blablabla:::::" + mapValues.get(1).getText());
		intent.putExtra("lapin1", (mapValues.get(1).getText() == "") ? "0" : mapValues.get(1).getText());
		intent.putExtra("lapin2", (mapValues.get(2).getText() == "") ? "0" : mapValues.get(2).getText());
		intent.putExtra("lapin3", (mapValues.get(3).getText() == "") ? "0" : mapValues.get(3).getText());
		intent.putExtra("lapin4", (mapValues.get(4).getText() == "") ? "0" : mapValues.get(4).getText());
		intent.putExtra("lapin5", (mapValues.get(5).getText() == "") ? "0" : mapValues.get(5).getText());
		intent.putExtra("lapin6", (mapValues.get(6).getText() == "") ? "0" : mapValues.get(6).getText());
		intent.putExtra("lapin7", (mapValues.get(7).getText() == "") ? "0" : mapValues.get(7).getText());

		setResult(RESULT_OK, intent);
	}

	@Override
	public void onRssItemSelectedLoups(Map<Integer, TextView> mapValues) {
		Intent intent = new Intent();

		intent.putExtra("loup1", (mapValues.get(1).getText() == "") ? "0" : mapValues.get(1).getText());
		intent.putExtra("loup2", (mapValues.get(2).getText() == "") ? "0" : mapValues.get(2).getText());
		intent.putExtra("loup3", (mapValues.get(3).getText() == "") ? "0" : mapValues.get(3).getText());
		intent.putExtra("loup4", (mapValues.get(4).getText() == "") ? "0" : mapValues.get(4).getText());
		intent.putExtra("loup5", (mapValues.get(5).getText() == "") ? "0" : mapValues.get(5).getText());
		intent.putExtra("loup6", (mapValues.get(6).getText() == "") ? "0" : mapValues.get(6).getText());
		intent.putExtra("loup7", (mapValues.get(7).getText() == "") ? "0" : mapValues.get(7).getText());
		setResult(RESULT_OK, intent);

	}

}
